import { isAdmin, checkIsLoginPage, checkIsLogin, toLogin, isMobile } from "@/common/utils";
import Footer from "@/components/footer";
import Header from "@/components/header";
import { Provider } from "mobx-react";
import { Outlet } from "umi";
import { Modal } from "antd-mobile";
import "./index.less";
import shores from "./stores";

let isShowScanCodeVisitTips = true;
export default function Layout() {
  const isLoginPage = checkIsLoginPage();
  const isLogined = isLoginPage || !isAdmin || (isAdmin && checkIsLogin());
  // 登录校验
  if (!isLogined) {
    return toLogin();
  }

  // 非移动端时提示扫码访问
  if(!isMobile() && isShowScanCodeVisitTips){
    Modal.show({
      image: isAdmin ? "/public/pictures/site/babyloveadmin.png" : "/public/pictures/site/babylove.png",
      title: "为获得更好的体验，请微信扫码访问",
      bodyClassName: "baby-love-scan-code-visit-tips",
    });
    isShowScanCodeVisitTips = false;
    return;
  }

  return (
    <Provider {...shores}>
      <div className={isAdmin ? "baby-love-admin" : "baby-love"}>
        {/* 头部 */}
        <Header />
        {/* 页面内容 */}
        <div className={isAdmin ? "baby-love-admin-body" : "baby-love-body"}>
          <Outlet />
        </div>
        {/* 底部 */}
        {isLoginPage ? null : <Footer />}
      </div>
    </Provider>
  );
}
